package com.wondersgroup.fjzlpt.console.dao.impl.menu;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.quick.framework.boot.repository.sql.bean.SQLBean;
import com.quick.framework.boot.repository.sql.bean.table.TableBean;
import com.quick.framework.boot.repository.sql.jdbcTemplate.impl.BaseJTDAOImpl;
import com.wondersgroup.fjzlpt.console.dao.inter.menu.MenuActionDAO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Repository;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by lion on 2017/5/15.
 */
@Repository
public class MenuActionDAOImpl extends BaseJTDAOImpl implements MenuActionDAO{
    @Override
    @Autowired
    @Qualifier("TB_AUTH_MENU_ACTION")
    public void setTb(TableBean tb) {
        super.setTb(tb);
    }

    /**
     * 插入
     * @param menuId
     * @param ary
     */
    public void insert(String menuId, JSONArray ary)
    {
        Map map = new HashMap();
        map.put("menuid", menuId);
        map.put("actions", ary.toString());
        this.insert(map);
    }

    /**
     * 根据菜单ID删除
     * @param menuId
     */
    public void deleteByMenuId(String menuId)
    {
        StringBuilder sbud = new StringBuilder("delete from ").append(this.tb.getTableName()).append(" where menuid=?");
        SQLBean sb = new SQLBean(sbud.toString(), new Object[]{menuId});
        this.update(sb);
    }
}
